<template>
	<div class="mtop" style=" padding:0.2rem 0.3rem; background: #fff;">
    <div class="flexbc">
      <!-- <div style="font-size: 0.35rem; font-weight: bold;">{{title}}</div> -->
      <div v-if="shangpinxiangqingShow" style="font-size: 0.35rem; font-weight: bold;" @click="$router.back(-1)"><{{title}}</div>
      <div v-else style="font-size: 0.35rem; font-weight: bold;">{{title}}</div>
      <div class="flexc">
        <!-- <div style="position: relative;"><img src="../../static/mimg/n6.png" style="width: 0.5rem; margin-left: 0.3rem;">
          <div style="position: absolute; top: -0.1rem; right: -0.1rem; background: #f00; color: #fff; font-size: 12px; width: 0.3rem; height: 0.3rem; border-radius: 0.3rem;" class="flexcc">1</div>
        </div> -->
        <!-- <div><img src="../../static/mimg/n7.png" style="width: 0.5rem; margin-left: 0.3rem;"></div> -->
        <div style="position: relative;"><img src="../../static/mimg/n14.png" style="width: 0.6rem; margin-left: 0.3rem;" @click="go('/tongzhi/mtongzhi')">
          <div style="position: absolute; top: -0.1rem; right: -0.1rem; background: #f00; color: #fff; font-size: 12px; width: 0.3rem; height: 0.3rem; border-radius: 0.3rem;" class="flexcc" v-if="list">{{list.length}}</div>
        </div>
      </div>
    </div>

      <van-popup v-model="log2" position="center" style="width: 6.5rem; padding: 0.3rem; border-radius: 0.2rem; font-size: 0.25rem;">
        <div style="padding: 0 0.3rem 0.6rem; ">
          <div style="margin-bottom: 20px;"><span style="font-weight: bold; margin-right: 10px; font-size: 0.3rem;">通知标题:</span>{{now.title}}</div>
          <div style="margin-bottom: 20px;" v-html="now.content"></div>
          <div style="margin-bottom: 20px;" class="flexc"  v-if="now.annex"><span style="font-weight: bold; margin-right: 10px;">附件:</span>
            <div @click="xiazai(now.annex)" style="color: rgb(0, 90, 255); cursor: pointer; margin-right: 20px;">下载</div>
          </div>
        </div>
        <div style="margin-top: 20px;text-align: center;">
          <el-button @click="log2 = false">取 消</el-button>
          <el-button type="primary" @click="yichakan">已查看</el-button>
          <el-button type="primary" @click="yichakan2">全部查看</el-button>
        </div>
      </van-popup>
	</div>
</template>

<script>
	export default {
		name: 'top',
		data() {
			return {
        title:"",
        list:"",
        now:"",
        log2:false,
        shangpinxiangqingShow:false
			}
		},
		created() {
      this.shangpinxiangqingShow = false

		},
		mounted() {
      document.title = localStorage.getItem('shop_name')
      if(this.$route.path.includes('/index')){
        this.title = '首页'
      }
      if(this.$route.path.includes('/tongzhi/mtongzhi')){
        this.title = '消息通知'
      }
      if(this.$route.path.includes('/dingdanguanli/dingdanchuli')){
        this.title = '订单管理'
      }
      if(this.$route.path.includes('/shangpinguanli/zaishoushangpin')){
        this.title = '商品'
      }
      if(this.$route.path.includes('/shangpinguanli/zaishoushangpinchakanziliao')){
        this.title = '商品详情'
        this.shangpinxiangqingShow = true
      }
      if(this.$route.path.includes('/fenxiaoshangguanli/fenxiaoshangguanli')){
        this.title = '分销商'
      }
      if(this.$route.path.includes('/geren/geren')){
        this.title = '我的'
      }
      this.getxiaoxi()
		},
		methods: {
      yichakan:function(){
        axios.get('/agent/message/read?id='+this.now.id).then((response)=>{
        	if (response.data.msg.code == 0) {
            this.log2 = false
            this.getxiaoxi()
        	} else {
        		this.$message.error(response.data.msg.info);
        	}
        })
      },
      yichakan2:function(){
        axios.get('/agent/message/read/all').then((response)=>{
        	if (response.data.msg.code == 0) {
            this.log2 = false
            this.getxiaoxi()
        	} else {
        		this.$message.error(response.data.msg.info);
        	}
        })
      },
      getxiaoxi:function(){
        axios.get('/agent/message/list?is_read=1').then((response)=>{
        	if (response.data.msg.code == 0) {
            if(response.data.data.data.length>0){
              this.list = response.data.data.data
              this.now = response.data.data.data[0]
              if(this.now.is_eject == 1){
                this.log2 = true
              }
            }
        	} else {
        		this.$message.error(response.data.msg.info);
        	}
        })
      },
      aaa(){

      }
		}
	}
</script>


<style scoped>
   img{ max-width: 100%;}
</style>
